/**
 *	api目录下的控制器
 *	开发者：雨中磐石
 *	地址：www.rockoa.com
 *	日期：2023-07-19
 */
package com.framework.Controller.api;


import com.framerock.db.DB;
import com.framerock.server.Response;
import com.framerock.baselib.CLog;
import com.framerock.baselib.Rock;
import com.framework.ACore.Controller;
import com.framework.ACore.Model;
import com.framework.Model.ModelLogin;

import java.util.Map;

public class ControllerApi extends Controller {

    public String admintoken = "";



    /**
     * 验证登录
     * */
    public String checkLogin()
    {
        String token                = mRequest.get("token");
        if(Rock.isEmpt(token))token = mRequest.post("token");
        this.admintoken             = token;
        if(Rock.isEmpt(token))return Response.returnError("token isempt", "201");

        ModelLogin lobj         = new ModelLogin(this.nDb);
        Map<String, String> lda = lobj.getOne("`token`='"+token+"'");
        if(lda==null)return Response.returnError("token invalid", "190");
        String uid = Rock.getMapString(lda, "uid", "0");

        Map<String, String> urs = Model.get(this.nDb, "users", mRequest).getOne("`id`="+uid+" and `status`=1");
        if(urs==null)return Response.returnError("token uid invalid", "190");
        lobj.update("`moddt`=now()", lda.get("id"));
        mRequest.setLogininfo(urs);

        String cnum             = mRequest.get("cnum");
        if(!Rock.isEmpt(cnum)){
            Map<String, String> crs = Model.get(this.nDb, "company").getOne("`num`='"+cnum+"' and `status`=1");
            if(crs == null)return Response.returnError("cnum invalid");
            mRequest.setCompanyinfo(crs);
            Map<String,String> ars = Model.get(this.nDb,"usera").getOne("`cid`="+mRequest.COMPANYID+" and `uid`="+uid+"");
            mRequest.setUserainfo(ars);
        }

        return "";
    }
}
